

import odoo
from odoo import http, _
from odoo.http import content_disposition, request
from odoo.exceptions import UserError, AccessError, ValidationError
from odoo.addons.studio_addon.controllers import export
from odoo.tools import ustr, sql

from odoo.addons.web_studio.controllers import main
import logging

_logging = logging.getLogger(__name__)


class WebStudioController(main.WebStudioController):

    @http.route('/web_studio/export', type='http', auth='user')
    def export(self, token):
        """ Exports a zip file containing the 'studio_customization' module
            gathering all customizations done with Studio (customizations of
            existing apps and freshly created apps).
        """
        studio_module = request.env['ir.module.module'].get_studio_module()
        data = request.env['ir.model.data'].search([('studio', '=', True)])
        content = export.generate_archive(studio_module, data)
        _logging.info('export')
        return request.make_response(content, headers=[
            ('Content-Disposition', content_disposition('customizations.zip')),
            ('Content-Type', 'application/zip'),
            ('Content-Length', len(content)),
        ], cookies={'fileToken': token})
        # return super(WebStudioController, self).export(token)
